(function() {
  'use strict';
  angular.module('controllers.dataManager.dataQualityApplication')
    .controller('alarmForecastCtrl', alarmForecastCtrl);

  function alarmForecastCtrl($scope, $filter, alarmForecastFactory, CoreService, CoreLoading) {
    $scope.initQuery = function() {
      CoreLoading.setState(true);
      var myEcharts = echarts.init(document.getElementById('predictionChart'));
      alarmForecastFactory.query(function(res) {
        if (res.data.state === '10000' && res.data.data.length >= 1) {
          CoreLoading.setState(false);
          var option = alarmForecastFactory.getArrayData(res.data.data);
          angular.forEach(option.series, function(sd) {
            angular.forEach(option.xAxis[0].data, function(xd, index) {
              if (sd.data[index] >= 20 || sd.data[index] <= -20) {
                sd.markPoint.data.push({
                  name: '告警',
                  value: sd.data[index],
                  xAxis: index,
                  yAxis: sd.data[index],
                  symbolSize: 30,
                  itemStyle: {
                    normal: {
                      color: 'red',
                      label: {
                        formatter: '{c}%'
                      },
                    }
                  }
                });
              }
            });
          });
          myEcharts.setOption(option);
        } else if (res.data.data.length === 0) {
          myEcharts && myEcharts.clear();
          CoreService.dialog('查询无数据');
        } else {
          myEcharts && myEcharts.clear();
          CoreService.dialog('查询错误');
        }
      });
    };
  }
})();
